package com.xuan.juc.homework;

import java.util.Random;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;

public class HomeWork1 {

    public static void main(String[] args) {
        A a = new A();
        B b = new B(a);

        new Thread(a).start();
        new Thread(b).start();
    }

}

class A implements Runnable {

    private static boolean loop = true;
    private static int cnt = 0;

    public void setLoop(boolean loop) {
        A.loop = loop;
    }

    @Override
    public void run() {

        while (loop) {

            System.out.println(cnt++);
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

}


class B implements Runnable {
    private Scanner scanner = new Scanner(System.in);
    private A a;

    public B(A a) {
        this.a = a;
    }

    @Override
    public void run() {
        char charAt = scanner.next().toUpperCase().charAt(0);
        if (charAt == 'Q') {
            a.setLoop(false);
        }


    }
}
